/*
 * java.c
 *
 * This file is (C) 2010 by the developers of pidgin-java.
 *
 * Pidgin, Finch, and libpurple are owned by their respective developers:
 * see http://pidgin.im
 *
 * This file is part of pidgin-java.
 *
 * pidgin-java is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * pidgin-java is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with pidgin-java.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "internal.h"
#include "java_jvm.h"
#include "version.h"

#define JAVA_PLUGIN_NAME		"Java Plugin Loader"
#define JAVA_PLUGIN_VERSION		"0.1"
#define JAVA_PLUGIN_ID			"lopl-jneuheisel-java"
#define JAVA_PLUGIN_CONTACT		"Joshua Neuheisel <joshua@neuheisel.us>"
#define JAVA_PLUGIN_SUMMARY		"Provides support for loading Java plugins"
#define JAVA_PLUGIN_DESCRIPTION	"Provides support for loading Java plugins"

static gboolean plugin_load(PurplePlugin *plugin);
static gboolean plugin_unload(PurplePlugin *plugin);
static void plugin_destroy(PurplePlugin *plugin);
static gboolean java_plugin_probe(PurplePlugin *plugin);
static gboolean java_plugin_load(PurplePlugin *plugin);
static gboolean java_plugin_unload(PurplePlugin *plugin);
static void java_plugin_destroy(PurplePlugin *plugin);

static PurplePluginLoaderInfo s_loader_info =
{
	NULL,
	java_plugin_probe,
	java_plugin_load,
	java_plugin_unload,
	java_plugin_destroy,
	NULL,
	NULL,
	NULL,
	NULL
};

static PurplePluginInfo s_info =
{
	PURPLE_PLUGIN_MAGIC,
	PURPLE_MAJOR_VERSION,
	PURPLE_MINOR_VERSION,
	PURPLE_PLUGIN_LOADER,
	NULL,
	0,
	NULL,
	PURPLE_PRIORITY_DEFAULT,
	N_(JAVA_PLUGIN_ID),
	NULL,
	N_(JAVA_PLUGIN_VERSION),
	NULL,
	NULL,
	N_(JAVA_PLUGIN_CONTACT),
	PURPLE_WEBSITE,
	plugin_load,
	plugin_unload,
	plugin_destroy,
	NULL,
	&s_loader_info,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL
};

static void
plugin_init(PurplePlugin *plugin)
{
	s_loader_info.exts = g_list_append(s_loader_info.exts, N_("jar"));

	s_info.name = g_strdup(_(JAVA_PLUGIN_NAME));
	s_info.summary = g_strdup(_(JAVA_PLUGIN_SUMMARY));
	s_info.description = g_strdup(_(JAVA_PLUGIN_DESCRIPTION));
}

static void
plugin_destroy(PurplePlugin *plugin)
{
	g_list_free(s_loader_info.exts);
	s_loader_info.exts = NULL;

	g_free(s_info.name);
	g_free(s_info.summary);
	g_free(s_info.description);
	s_info.name = N_(JAVA_PLUGIN_NAME);
	s_info.summary = N_(JAVA_PLUGIN_SUMMARY);
	s_info.description = N_(JAVA_PLUGIN_DESCRIPTION);
}

static gboolean
plugin_load(PurplePlugin *plugin)
{
	return java_jvm_load();
}

static gboolean
plugin_unload(PurplePlugin *plugin)
{
	return java_jvm_unload();
}

static gboolean
java_plugin_probe(PurplePlugin *plugin)
{
	return java_jvm_probe_plugin(plugin);
}

PURPLE_INIT_PLUGIN(java, plugin_init, s_info)
